package com.etl.dataflow.scheduler.admin.entity.vo;

import com.etl.dataflow.scheduler.admin.entity.DataflowExecutorInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.math.RoundingMode;

@EqualsAndHashCode(callSuper = true)
@Data
public class DataflowExecutorInfoVo extends DataflowExecutorInfo implements Comparable<DataflowExecutorInfoVo> {
    /**
     * CPU使用率(%)
     */
    private BigDecimal cpuUsage;

    /**
     * 内存总量
     */
    private BigDecimal totalMemory;

    /**
     * 已用内存空间
     */
    private BigDecimal usedMemory;

    /**
     * 任务数量
     */
    private Integer taskNumber;

    @Override
    public int compareTo(DataflowExecutorInfoVo o2) {
        DataflowExecutorInfoVo o1 = this;
        double o1MemoryUsage = o1.getUsedMemory().divide(o1.getTotalMemory(), RoundingMode.HALF_UP).doubleValue();
        double o2MemoryUsage = o2.getUsedMemory().divide(o2.getTotalMemory(), RoundingMode.HALF_UP).doubleValue();
        double o1Usage = o1MemoryUsage * 0.9 + o1.getCpuUsage().doubleValue() * 0.1;
        double o2Usage = o2MemoryUsage * 0.9 + o2.getCpuUsage().doubleValue() * 0.1;
        return Double.compare(o1Usage, o2Usage);
    }
}
